@extends("backend.layout.main")

@section("before.css")

    <link type="text/css" href="backend/css/animate.min.css" rel="Stylesheet">
    <link type="text/css" href="/backend/css/normalize.css" rel="Stylesheet">
    <link type="text/css" href="/backend/css/webuploader.css" rel="Stylesheet">
    @endsection


    @section("right_content")
            <!--middle-->
    <div class="mainWrapBox">
        <div class="mainBox">

            <h1>
                <a href="/backend/items/">项目</a> / {{ $itemInfo['item_name'] }}
                <span class="projects-nav">
<a href="/backend/work/download/{{ $itemInfo['id'] }}">文档</a>
    <a class="current-nav" href="/backend/items/task/{{ $itemInfo['id'] }}">任务</a>

    <a href="/backend/items/show/{{ $itemInfo['id'] }}">基本信息</a>
</span>    </h1>


            <div class="html">
                <div class="w220 f_l" id="task-list-left">
                    <div class="listWrapbox mt10" id="main-left" style="height: 860px;">
                        <h2>阶段</h2>

                        <ul class="task-stage ui-sortable" id="task-stage">
                            <li class="selected sort-disabled" onclick="filter(this,&#39;more&#39;);"><a data-id="-1">全部</a></li>
                            @foreach($stagesarr as $item=>$value)
                                <li onclick="filter(this,&#39;more&#39;);" class="sort-able">
                                    <em class="icon-move"></em>
                                    <a data-id="{{$item}}" title="概念方案设计" style="padding-top: 5px;">
                                        <div class="content-2line" style="font-size: 14px;">{{$value}}</div>
                                    </a>
                                </li>
                            @endforeach
                        </ul>

                    </div>
                </div>
                <div class="auto-width-220" id="task-list-right">
                    <div class="proect-list-wrap-box mt10" id="main-right">

                        <div class="project-task-list">
                            <h2>任务 </h2>
                            <form id="createTaskForm">

                                <div class="mt10">
                                    <table class="task-add" width="100%">
                                        <tbody><tr>
                                            <td>
                                                <input type="hidden" value="430" name="fkId">

                                                @if(session()->get('member')['gid']==1)
                                                    <input type="text" class="ml10" name="title" placeholder="输入任务名称,按Enter提交" style="border:none;min-width:150px;width:100%" id="createTask">
                                                @else
                                                    <input type="hidden" style="border:none;min-width:150px;width:100%" >
                                                @endif

                                            </td>
                                            <td width="80px"></td>
                                            <td width="100px" style="line-height: 20px">
                                                <div class="drop-select-container clearfix">
                                                    <div data-toggle="drop-select" class="drop-select" ><span class="selected-text">任务人</span></div>

                                                </div>
                                            </td>
                                            <td width="200px">审核人</td>
                                            <td width="140px">
                                                <input type="hidden" name="expectFinishDate" id="expectFinishDate">
                                                <span>截止日期</span>
                                            </td>
                                            <td width="140px">

                                                <span>状态</span>
                                            </td>
                                            <td width="18px"></td>
                                        </tr>
                                        </tbody></table>
                                    <input type="hidden" class="createTask">
                                    <input type="hidden" name="templeteId" value="0">
                                    <input type="hidden" name="taskStep" value="0">
                                </div>
                            </form>
                            <div class="task-list">
                                <form id="createSubTaskForm">

                                    <table width="100%">
                                        <thead>
                                        <tr>
                                            <th style="min-width:200px;"></th>
                                            <th width="80px"></th>
                                            <th width="100px"></th>
                                            <th width="200px"></th>
                                            <th width="140px"></th>
                                            <th width="140px"></th>
                                            <th width="25px"></th>
                                        </tr>
                                        </thead>

                                        <tbody id="task_list">
                                        @foreach($itemTasks as $k=>$v)
                                            @if($v['task_status']==-10)
                                                <tr class="parent-task stages_{{$v['stage_id']}}" data-renwu="{{$v['type_id']}}" data-id="{{ $v['id'] }}" data-pid="0" data-shenhe="{{$v['role_id']}}" data-sub="-1" data-parent="1" >
                                                    <td  >
                                                        <div class="task-input-ms f_l mt5">
                                                            <div type="text" class="task-input shows-pak" title="设置任务状态">
                                                                <img src="backend/images/ta2.png" class="shows-pak">
                                                            </div>

                                                        </div>
                                                        <div class="ml40 content-2line" style="display: block;margin-top: 5px;">
                                                            <a data-toggle="modal-task" title="T1 3月8号前完成首轮总图设计手稿" data-target="#taskPanel" data-url="http://www.xcube.com.cn/project/task/detail/5/430/2622" ><span style="text-decoration: line-through; color: rgb(204, 204, 204);">{{ $v['task_name'] }}</span></a>
                                                        </div>
                                                    </td>
                                                    @if(session()->get('member')['gid']==1)
                                                        <td class="add-sub-task" >+子任务</td>
                                                    @else
                                                        <td></td>
                                                    @endif
                                                    <td >
                                                        <div class="drop-select-container clearfix">
                                                            <div ><span class="selected-text" style="text-decoration: line-through; color: rgb(204, 204, 204);">{{ empty($v['name1']) ? '待定':$v['name1'] }}</span></div>
                                                            <div class="drop-select-div Pop_ddowm_box Pop_up_box w100">
                                                                <div class="mt10 ml10"><input type="text" class="w80" placeholder="查找负责人"></div>
                                                                <ul class="drop-select-menu">

                                                                    @foreach($roles[$v['type_id']] as $i=>$y)
                                                                        <li data-uid="{{ $y['uid'] }}"><a href="javascript:;" style="text-decoration: line-through; color: rgb(204, 204, 204);">{{ $y['username'] }}</a></li>
                                                                    @endforeach
                                                                </ul>
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td >
                                                        <div class="drop-select-container clearfix">
                                                            <div class="drop-select" ><span class="selected-text" style="text-decoration: line-through; color: rgb(204, 204, 204);">{{ empty($v['name2']) ? '待定':$v['name2'] }}</span></div>

                                                            <div class="drop-select-div Pop_ddowm_box Pop_up_box w100">
                                                                <div class="mt10 ml10"><input type="text" class="w80" placeholder="查找审核人"></div>
                                                                <ul class="drop-select-menu" select-type="multiple">
                                                                    @foreach($roles[$v['role_id']] as $i=>$y)
                                                                        <li data-uid="{{ $y['uid'] }}"><a href="javascript:;">{{ $y['username'] }}</a></li>
                                                                    @endforeach
                                                                </ul>


                                                            </div>
                                                        </div>
                                                    </td>

                                                    @if(session()->get('member')['gid']==1)
                                                        <td class="td-date-{{$v['id']}}" style="text-decoration: line-through; color: rgb(204, 204, 204);">{{ $v['task_deadline']}}</td>
                                                        <td><p>{{ trans('items.taskStatus_'.$v['task_status']) }}</p></td>
                                                        <td><span class="icon-add hide" style="background-image:url('backend/images/icon_add.png')"></span></td>
                                                    @else
                                                        <td class="td-date-{{$v['id']}}">{{ $v['task_deadline']}}</td>
                                                        <td><p>{{ trans('items.taskStatus_'.$v['task_status']) }}</p></td>
                                                        <td></td>
                                                    @endif
                                                </tr>
                                            @else
                                                <tr class="parent-task stages_{{$v['stage_id']}}" data-renwu="{{$v['type_id']}}" data-id="{{ $v['id'] }}" data-pid="0" data-shenhe="{{$v['role_id']}}" data-sub="-1" data-parent="1" style="background-color: rgb(255, 255, 255);">
                                                    <td>
                                                        <div class="task-input-ms f_l mt5">
                                                            <div type="text" class="task-input shows-pak" title="设置任务状态">
                                                                <img src="backend/images/ta2.png" class="shows-pak">
                                                            </div>

                                                        </div>
                                                        <div class="ml40 content-2line" style="display: block;margin-top: 5px;">
                                                            <a data-toggle="modal-task" title="T1 3月8号前完成首轮总图设计手稿" data-target="#taskPanel" data-url="http://www.xcube.com.cn/project/task/detail/5/430/2622">{{ $v['task_name'] }}</a>
                                                        </div>
                                                    </td>
                                                    @if(session()->get('member')['gid']==1)
                                                        <td class="add-sub-task">+子任务</td>
                                                    @else
                                                        <td></td>
                                                    @endif
                                                    <td>
                                                        <div class="drop-select-container clearfix">
                                                            <div @if(session()->get('member')['gid']==1) data-toggle="drop-select" @endif class="drop-select" ><span class="selected-text">{{ empty($v['name1']) ? '待定':$v['name1'] }}</span></div>
                                                            <div class="drop-select-div Pop_ddowm_box Pop_up_box w100">
                                                                <div class="mt10 ml10"><input type="text" class="w80" placeholder="查找负责人"></div>
                                                                <ul class="drop-select-menu">

                                                                    @foreach($roles[$v['type_id']] as $i=>$y)
                                                                        <li data-uid="{{ $y['uid'] }}"><a href="javascript:;">{{ $y['username'] }}</a></li>
                                                                    @endforeach
                                                                </ul>
                                                            </div>
                                                        </div>
                                                    </td>
                                                    <td>
                                                        <div class="drop-select-container clearfix">
                                                            <div @if(session()->get('member')['gid']==1) data-toggle="drop-select" @endif class="drop-select" ><span class="selected-text">{{ empty($v['name2']) ? '待定':$v['name2'] }}</span></div>

                                                            <div class="drop-select-div Pop_ddowm_box Pop_up_box w100">
                                                                <div class="mt10 ml10"><input type="text" class="w80" placeholder="查找审核人"></div>
                                                                <ul class="drop-select-menu" select-type="multiple">
                                                                    @foreach($roles[$v['role_id']] as $i=>$y)
                                                                        <li data-uid="{{ $y['uid'] }}"><a href="javascript:;">{{ $y['username'] }}</a></li>
                                                                    @endforeach
                                                                </ul>


                                                            </div>
                                                        </div>
                                                    </td>

                                                    @if(session()->get('member')['gid']==1)
                                                        <td class="td-date-{{$v['id']}}" onClick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss',isclear: false, choose:function(datas){updateTime({{$v['id']}}, datas)}});">{{ $v['task_deadline']}}</td>
                                                        <td><p>{{ trans('items.taskStatus_'.$v['task_status']) }}</p></td>
                                                        <td><p class="icon-remove2 hide"></p></td>
                                                    @else
                                                        <td class="td-date-{{$v['id']}}">{{ $v['task_deadline']}}</td>
                                                        <td><p>{{ trans('items.taskStatus_'.$v['task_status']) }}</p></td>
                                                        <td></td>
                                                    @endif
                                                </tr>
                                            @endif
                                            @if($v['childs'])
                                                @foreach($v['childs'] as $i=>$y)
                                                    <tr class="sub-task stages_{{$y['stage_id']}}" data-stage="27" data-id="{{$y['id']}}" data-pid="{{ $v['id'] }}" data-parent="1" style="background-color: rgb(255, 255, 255);">
                                                        <td>
                                                            <div class="task-input-ms f_l mt5">
                                                                <div type="text" class="task-input shows-pak" title="设置任务状态">
                                                                    <img src="./images/ta2.png" class="shows-pak">
                                                                </div>

                                                            </div>
                                                            <div class="ml40 content-2line" style="display: block;margin-top: 5px;">
                                                                <a data-toggle="modal-task" title="T2 123" data-target="#taskPanel" >{{ $y['task_name'] }}</a>
                                                            </div>
                                                        </td>
                                                        <td></td>
                                                        <td>
                                                            <div class="drop-select-container clearfix">
                                                                <div @if(session()->get('member')['gid']==1) data-toggle="drop-select" @endif class="drop-select"><span class="selected-text">{{ $y['child_name1'] }}</span></div>
                                                                <div class="drop-select-div Pop_ddowm_box Pop_up_box w100">
                                                                    <div class="mt10 ml10"><input type="text" class="w80" placeholder="查找负责人"></div>
                                                                    <ul class="drop-select-menu">
                                                                        @foreach($roles[$v['type_id']] as $a=>$b)
                                                                            <li data-uid="{{ $b['uid'] }}"><a href="javascript:;">{{ $b['username'] }}</a></li>
                                                                        @endforeach
                                                                    </ul>
                                                                </div>
                                                            </div>
                                                        </td>
                                                        <td>
                                                            <div class="drop-select-container clearfix">
                                                                <div @if(session()->get('member')['gid']==1) data-toggle="drop-select" @endif class="drop-select"><span class="selected-text">{{ $y['child_name2'] }}</span></div>
                                                                <div class="drop-select-div Pop_ddowm_box Pop_up_box w100">
                                                                    <div class="mt10 ml10"><input type="text" class="w80" placeholder="查找审核人"></div>
                                                                    <ul class="drop-select-menu" select-type="multiple">
                                                                        @foreach($roles[$v['role_id']] as $a=>$b)
                                                                            <li data-uid="{{ $b['uid'] }}"><a href="javascript:;">{{ $b['username'] }}</a></li>
                                                                        @endforeach
                                                                    </ul>
                                                                </div>
                                                            </div>
                                                        </td>
                                                        @if(session()->get('member')['gid']==1)
                                                            <td class="td-date-{{$y['id']}}" onClick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss',isclear: false, choose:function(datas){updateTime({{$y['id']}}, datas)}});">{{ $y['task_deadline']}}</td>
                                                            <td><p>{{ trans('items.taskStatus_'.$y['task_status']) }}</p></td>
                                                            <td><p class="icon-remove2 hide"></p></td>
                                                        @else
                                                            <td>{{ $y['task_deadline']}}</td>
                                                            <td><p>{{ trans('items.taskStatus_'.$y['task_status']) }}</p></td>
                                                            <td></td>
                                                        @endif
                                                    </tr>
                                                @endforeach
                                            @endif
                                        @endforeach

                                        </tbody>
                                        <tfoot>
                                        <tr>
                                            <td class="text-center task-page" colspan="2">
                                            </td>
                                        </tr>
                                        </tfoot>
                                    </table>
                                </form>
                                <div class="template-page mt20">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <table style="display: none;" id="tmpSubTask">
                <tbody>
                <tr class="sub-task">
                    <td colspan="2">
                        <input type="text" class="ml10 w400 createSubTask child_name"  name="subTasks[0].title" placeholder="输入子任务名称,按Enter提交" style="border:none">
                        <input type="hidden" name="subTasks[0].fkId" value="430">
                    </td>
                    <td>
                        <div class="drop-select-container clearfix">
                            <div data-toggle="drop-select" class="drop-select" style="background:url(&#39;http://www.xcube.com.cn//upload/2015/10/23/d443f829-0ae4-47cc-b1e8-90c4515a7894.jpg&#39;) no-repeat scroll 0 12px;padding-left: 15px;background-size:12px,15px;">
                                <span class="selected-text">请选择</span>
                            </div>
                            <div class="drop-select-div Pop_ddowm_box Pop_up_box w100">
                                <div class="mt10 ml10"><input type="text" class="w80" placeholder="查找负责人"></div>
                                <input type="hidden" name="members[0].role" value="1">
                                <input type="hidden" id="taskChargeName_0" class="child_username" name="subTasks[0].taskChargeName" value="">
                                <input type="hidden" id="userId_0" class="child_userid" name="subTasks[0].userId" value="">
                                <ul class="users">
                                </ul>
                            </div>
                        </div>
                    </td>
                    <td>

                    </td>
                    <td>
                        <input class="date" type="text" placeholder="截止时间，以小时计算">

                    </td>
                    <td>
                        <input type="hidden" name="subTasks[0].taskStep" value="0">
                        <input type="hidden" name="subTasks[0].pid" id="pid_0">
                        <input type="button" class="save1" value="添加">
                        <input type="button" class="esc1" value="取消">
                    </td>
                </tr>
                </tbody>
            </table>
            <script type="text/javascript" src="/backend/js/jquery-1.11.2.min.js"></script>
            <script src="/backend/js/info.js"></script>
            <script src="/backend/js/laydate.js"></script>
            <script src="/backend/js/function.js"></script>
            <script type="text/javascript">
                var json=<?php echo json_encode($roles)?>;


                $(document).on('click', '.users li', function () {
                    var v=$(this).text();
                    var i=$(this).parent().parent().parent().find('span').text(v);
                    var uid=$(this).data('uid');
                    var username=$(this).find('a').text();
                    $('.child_username').val(username);
                    $('.child_userid').val(uid);
                });
                $(document).on('click', '.save1', function () {
                    var pid=$(this).parent().parent().data('pid');
                    var child_name=$('.child_name').val();
                    var child_username=$('.child_username').val();
                    var child_userid=$('.child_userid').val();
                    var date=$('.date').val();
                    var _Token="{{ csrf_token() }}";
                    $.post('/backend/items/child_task',{pid:pid,child_name:child_name,child_userid:child_userid,date:date,_Token:_Token},function(data){
                        if(data>0){
                            location.href="/backend/items/task/{{ $itemInfo['id'] }}";
                        }else {
                            alert('操作失败，请重试！');
                            location.href="/backend/items/task/{{ $itemInfo['id'] }}";
                        }
                    })

                });
                $(document).on('click', '.esc1', function () {
                    $(this).parent().parent().remove();
                });


                $(document).on('click','.content-2line a',function(){
                    $('#taskPanel').animate({
                        right:'0px',
                    });
                });
                $('.task-title-close').click(function(){
                    $('#taskPanel').animate({
                        right:'-550px',
                    });
                });




                $(document).on('click', '.add-sub-task', function () {
                    var ptask = $(this).parent();
                    var pid = ptask.data("id");
                    var renwu=ptask.data('renwu');
                    var tex="";
                    $.each(json[renwu],function(k,v){
                        tex +="<li data-uid="+ v.uid+"><a href='javascript:;'>"+ v.username+"</a></li>";
                    });
                    $('.users').empty();
                    $('.users').append(tex);
                    var html = $("#tmpSubTask").find("tr").eq(0).html();


                    html = '<tr class="sub-task" edit_flag="1" data-id="0" data-pid="'+pid+'" data-stage="">' + html + '</tr>';
                    var subTasks = $("#task_list [data-pid=" + pid + "]");
                    var insertObj;
                    if (subTasks.length > 0) {
                        insertObj = $("#task_list [data-pid=" + pid + "]:last");
                        insertObj.after(html);
                    } else {
                        insertObj = $("#task_list [data-id=" + pid + "]");
                        insertObj.after(html);
                    }

                    $("#pid_0").val(pid);
                    $("#task_list [edit_flag=1]").find("input:first")[0].focus();
                });
                /**
                 * 绑定click事件
                 * 修改任务 / 审核人
                 */
                $(document).on("click",".drop-select-menu li",function (e) {
                    //$(this).information('dropOption');
                    var mul = $(this).parent().attr('select-type');
                    var arguments = '';

                    if(mul == 'multiple'){
                        var cls = $(this).find('a').hasClass('selected');
                        if(cls){
                            $(this).find('a').removeClass('selected');
                        }else{
                            $(this).find('a').addClass('selected');
                        }
                        arguments = 'check_id';
                    }else{
                        $(this).parent().find('a').removeClass('selected');
                        $(this).find('a').addClass('selected');
                        arguments = 'task_id';
                    }

                    var ids = [];
                    var name =[];

                    $(this).parent().find('a.selected').each(function(){
                        ids.push($(this).parent().attr('data-uid'));
                        name.push($(this).text());
                    })

                    if( ids.length ==0 ){
                        alert('未有选中人');
                        return false;
                    }

                    var _this = $(this);
                    var id = _this.parent().parent().parent().parent().parent().attr('data-id');
                    //alert(id);
                    var _Token="{{ csrf_token() }}";
                    $.post('backend/items/edittask', {'id':id,'type':arguments, 'role_ids':ids,_Token:_Token},function(d){

                        if(d==1)
                            _this.parent().parent().prev().find('span').text(name);
                        else
                            alert('未知错误');

                    })
                    e.stopPropagation();
                });
                /*  //修改时间
                 function updateTime(id,data){
                 // console.log(id+' - '+ data);
                 $.post('backend/items/edittask', {'id':id,'type':'time', 'date':data},function(){})
                 }
                 */

                $(document).on("click",'[data-toggle="drop-select"]',function (e) {
                    $(this).information('dropSelect');
                    e.stopPropagation();
                });

                $(document).on("mouseover", "#task_list tr,.task-member-list li", function () {
                    $(this).find(".icon-remove2").toggleClass("hide");
                    $(this).css("background-color","#e4e4e4");
                });

                $(document).on("mouseout", "#task_list tr,.task-member-list li", function () {
                    $(this).find(".icon-remove2").toggleClass("hide");
                    $(this).css("background-color","#ffffff");
                });

               //取消删除的鼠标事件
                $(document).on("mouseover", "#task_list tr,.task-member-list li", function () {
                    $(this).find(".icon-add").toggleClass("hide");
                    $(this).css("background-color","#e4e4e4");
                });
                //取消删除的鼠标事件
                $(document).on("mouseout", "#task_list tr,.task-member-list li", function () {
                    $(this).find(".icon-add").toggleClass("hide");
                    $(this).css("background-color","#ffffff");
                })

                /* 恢复任务 */
                $(document).on("click", "#task_list .icon-add", function () {

                    if(confirm("你要恢复任务吗？")){
                        var _Token="{{ csrf_token() }}";
                        var that = $(this).parents("tr");
                        var id = that.data("id");
                        $.post('backend/items/task_back',{id:id,_Token:_Token},function(data){
                            if(data>0){
                                that.remove();
                            }
                            location.reload();
                        })
                    }

                });

                $(document).on("mouseleave",".drop-div",function(){
                    $(this).hide();
                });
                $(document).on("click",".task-doc .drop-div li a",function(){
                    $(this).parents(".drop-div").hide();
                });

                /* 删除任务 */
                $(document).on("click", "#task_list .icon-remove2", function () {

                    if(confirm("你要删除该任务吗？")){
                        var _Token="{{ csrf_token() }}";
                        var that = $(this).parents("tr");
                        var id = that.data("id");
                        $.post('backend/items/task_delete',{id:id,_Token:_Token},function(data){
                            if(data>0){
                                that.remove();
                            }
                            location.reload();
                        })
                    }

                });

                //添加任务
                $("#createTaskForm").keyup(function(e){
                    var e=e || event,
                            keycode=e.which || e.keyCode;
                    if(keycode==13){
                        $('.createTask').trigger('click');
                    }
                });



                //添加子任务
                $(document).on("keyup",".createSubTask",function(e){
                    var e=e || event,keycode=e.which || e.keyCode;
                    if(keycode==13){
                        createSubTask();
                    }
                });



                $(document).on('click',function(e){
                    var ofs=$(e.target).parents().hasClass("bb_con");
                    var ofg=$(e.target).hasClass("bb_con");
                    var osg=$(e.target).hasClass("shows-pak");
                    if(!osg) {
                        if(ofs || ofg){

                        }
                        else{
                            $(".bb_con").hide();
                        }
                    }
                });

                $("body").click(function(){
                    $(".Pop_up_box").hide();
                })

                $('input[placeholder="查找负责人"]').click(function(){
                    event.stopPropagation();
                });
                $('input[placeholder="查找审核人"]').click(function(){
                    event.stopPropagation();
                });

                //add 2016-9-18  chen
                function saveDetailData(obj) {
                    var id=$(obj).data('taskid');
                    var data=$(obj).val();
                    if(data){

                        var data1=data+"小时";
                    }else {

                        var data1="待定";

                    }

                    $(obj).addClass('hide');
                    $(obj).prev().html(data1).removeClass('hide');
                    //修改时间
                    $.post('backend/items/edittask', {'id':id,'type':'time', 'date':data},function(){})
                }
                function editDetailData(obj) {

                    var text=($(obj).children().eq(0).html().split('小')[0]);
                    $(obj).children().eq(1).val(text).removeClass('hide');
                    $(obj).children().eq(0).addClass('hide');
                    $(obj).children().eq(1).focus()
                }

                //end
            </script>

@endsection